package base.study.chapter6;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

/**
 * @description TODO(用一句话描述方法的主要功能)
 */
public class TalkClock {

    class TimePrinter implements ActionListener{
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("打印什么东西：" + new Date());
            System.out.println("响一下");
        }
    }

    public static void main(String... args) throws InterruptedException {
        ActionListener listener = new TalkClock().new TimePrinter();
        Timer timer = new Timer(1000,listener);
        timer.start();

    }

    public void start(int interval,boolean beep) {
        class TimePrinter implements ActionListener{

            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("--");
                if(beep){
                    Toolkit.getDefaultToolkit().beep();
                }
            }
        }

        ActionListener listener = new TimePrinter();
        Timer t = new Timer(interval, listener);
        t.start();
    }
}
